home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / Transfer / Main.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  10KB  |  371 lines

  1. /*
  2.  
  3.   Transfer
  4.   ========
  5.  
  6.   the interface between a program that wants a file transfered between both computers
  7.   and the protocol drivers
  8.  
  9.   E.G. the UPLOAD door calls TRANSFR which then calls the correct protocol driver
  10.        depending on what protocol the user has selected
  11.  
  12.  
  13.   N_ND->ActiveDoor->SystemOptions
  14.   ===============================
  15.  
  16.   No options used at this time
  17.  
  18.  
  19.   Door Options (Command Line)
  20.   ===========================
  21.  
  22.   UPLOAD|DOWNLOAD|BOTH
  23.  
  24.   ProtocolNumber
  25.  
  26.   WAREZ|NONWAREZ
  27.  
  28.   [CHECKFILES]
  29.  
  30.   [NOLOGOFF]
  31.  
  32.   if the "checkfiles" keyword is present after parameter 2 we have to tell the
  33.   protocol door to call the "CHECK_FILES" door after each file has been uploaded
  34.   so that it can do background filechecking.
  35.   *C* Implement!!!
  36.  
  37.   if NONWAREZ is specified then uploaded files get put in the playpen's/NonWarez dir
  38.   otherwise they go straight into the playpen.
  39.  
  40.   if NOLOGOFF is specified then you won't get the option to [G]oodbye...
  41.  
  42.   Example
  43.   =======
  44.  
  45.   TRANSFER UPLOAD 2 CHECKFILES
  46.  
  47.   Notes
  48.   =====
  49.  
  50.   you MUST check that the protocol selected can cope with the type of transfer
  51.   Check UPLOAD|DOWNLOAD|BOTH against the following
  52.  
  53.   BBSGlobal->ProtocolList->ProtocolNode->protocoltype
  54.   BBSGlobal->ProtocolList->ProtocolNode->allow_ul
  55.   BBSGlobal->ProtocolList->ProtocolNode->allow_dl
  56.  
  57.   Also check the following
  58.  
  59.   BBSGlobal->ProtocolList->ProtocolNode->allow_batch
  60.  
  61.   if allow_batch is off and the transfer type is DOWNLOAD you must call the protocol
  62.   door for each file that the user wants download...
  63.  
  64.  
  65.   Hehe and now to confuse you..  to the USER pressing U starts the UPLOAD door,
  66.   which means the USER is going to UPLOAD some files therefore we mus start the
  67.   protocol DOWNLOAD door, rahter than an UPLOAD protocol :-) hehe  and vise versa!
  68.  
  69.  
  70. */
  71.  
  72.  
  73. #include <exec/types.h>
  74. #include <exec/memory.h>
  75. #include <dos/dos.h>
  76. #include <clib/exec_protos.h>
  77. #include <clib/dos_protos.h>
  78. #include <clib/alib_protos.h>
  79.  
  80. #include <stdlib.h>
  81. #include <string.h>
  82. #include <stdio.h>
  83. #include <ctype.h>
  84. #include <time.h>
  85.  
  86.  
  87. #ifdef __SASC
  88. int CXBRK(void) { return(0); }
  89. int _CXBRK(void) { return(0); }
  90. void chkabort(void) {}
  91. #endif
  92.  
  93. #include <HBBS/ANSI_Codes.h>
  94. #include <HBBS/Defines.h>
  95. #include <HBBS/types.h>
  96. #include <HBBS/structures.h>
  97. #include <HBBS/hbbscommon_protos.h>
  98. #include <HBBS/hbbscommon_pragmas.h>
  99. #include <HBBS/Hbbsnode_protos.h>
  100. #include <HBBS/Hbbsnode_pragmas.h>
  101. #include <HBBS/release.h>
  102. char *versionstr="$VER: Transfer "RELEASE_STR;
  103.  
  104. struct Library *HBBSCommonBase=NULL;
  105. struct Library *HBBSNodeBase=NULL;
  106.  
  107. struct BBSGlobalData *BBSGlobal=NULL;
  108. struct NodeData *N_ND=NULL;
  109. int N_NodeNum=-1;
  110. char outstr[1024]; // temp string for displaying text..
  111.  
  112. #define T_NONE 0
  113. #define T_UPLOAD 1
  114. #define T_DOWNLOAD 2
  115. #define T_BOTH 3
  116.  
  117. #define T_WAREZ 1
  118. #define T_NONWAREZ 2
  119.  
  120. short transfertype=T_NONE;
  121. short filetype=T_NONE;
  122.  
  123. struct ProtocolNode *PNode=NULL;
  124. V_BIGNUM PNum;
  125.  
  126. static VOID cleanup(ULONG num)
  127. {
  128.   if (HBBSNodeBase)
  129.   {
  130.     HBBS_CleanUpDoor();
  131.     CloseLibrary (HBBSNodeBase);
  132.   }
  133.  
  134.   if (HBBSCommonBase)
  135.   {
  136.     HBBS_CleanUpCommon();
  137.     CloseLibrary (HBBSCommonBase);
  138.   }
  139.  
  140.   if (num) printf("Door Error = %d\n",num);
  141.  
  142.   exit(0);
  143. }
  144.  
  145. static VOID init(char *name)
  146. {
  147.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  148.   {
  149.     cleanup(1);
  150.   }
  151.  
  152.   if (!(HBBS_InitCommon()))
  153.   {
  154.     cleanup(2);
  155.   }
  156.  
  157.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  158.   {
  159.     cleanup(3);
  160.   }
  161.  
  162.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  163.   {
  164.     cleanup(4);
  165.   }
  166.   SetProgramName(name);
  167. }
  168.  
  169. void DoorMain(int argc,char *argv[])
  170. {
  171.   char options[4096]; // *C* v.big string!
  172.   struct TaggedFile *Tag;
  173.   char inputstr[10];
  174.   V_BIGNUM doorret,loop;
  175.   BOOL StillOK,allowgoodbye=TRUE;
  176.  
  177.   if (argc<4)
  178.   {
  179.     DOOR_WriteText("Invalid Parameters, Check your config!\r\n");
  180.   }
  181.   else
  182.   {
  183.     for (loop=3;loop<argc;loop++)
  184.     {
  185.       if (stricmp(argv[loop],"NOGOODBYE")==0) allowgoodbye=FALSE;
  186.     }
  187.  
  188.     if (stricmp(argv[2],"UPLOAD")==0) transfertype=T_UPLOAD;
  189.     if (stricmp(argv[2],"DOWNLOAD")==0) transfertype=T_DOWNLOAD;
  190.     if (stricmp(argv[2],"BOTH")==0) transfertype=T_BOTH;
  191.  
  192.     if (transfertype!=T_NONE)
  193.     {
  194.       PNum=atoi(argv[3]);
  195.  
  196.       if (PNum>=0 && PNum<BBSGlobal->Protocols)
  197.       {
  198.         PNode=(struct ProtocolNode *)GetNode(BBSGlobal->ProtocolList,PNum);
  199.  
  200.         if (
  201.             (
  202.              (transfertype==T_UPLOAD) &&
  203.              (PNode->allow_ul)
  204.             )
  205.             ||
  206.             (
  207.              (transfertype==T_DOWNLOAD) &&
  208.              (PNode->allow_dl)
  209.             )
  210.             ||
  211.             (
  212.              (transfertype==T_BOTH) &&
  213.              (PNode->allow_dl) &&
  214.              (PNode->allow_ul) &&
  215.              (PNode->protocoltype == PTYPE_BIDIRECTIONAL)
  216.             )
  217.            )
  218.         {
  219.           // Protocol Checks out, so let's gooooo
  220.  
  221.           if (stricmp("NONWAREZ",argv[4])==0) filetype=T_NONWAREZ;
  222.           if (stricmp("WAREZ",argv[4])==0) filetype=T_WAREZ;
  223.  
  224.           if (filetype!=T_NONE)
  225.           {
  226.             strcpy(N_ND->CharsAllowed,"SsAa ");
  227.             strcpy(outstr,"[S]tart Transfer, ");
  228.             if (allowgoodbye)
  229.             {
  230.               strcat(outstr,"[G]oodbye after transfer, ");
  231.               strcat(N_ND->CharsAllowed,"Gg");
  232.             }
  233.             strcat(outstr,"[A]bort >");
  234.             DOOR_MenuPrompt(outstr,'S');
  235.  
  236.             DOOR_GetLine(GL_USECHARS|GL_IMMEDIATE,'\0',1,0,NULL);
  237.             if (N_ND->OnlineStatus==OS_ONLINE)
  238.             {
  239.               strNcpy(inputstr,N_ND->CurrentLine,2);
  240.               switch(toupper(inputstr[0]))
  241.               {
  242.                 case 'A':
  243.                   DOOR_WriteText("Aborted!\r\n");
  244.                   break;
  245.                 case 'G':
  246.                   DOOR_WriteText("Goodbye after xfer!\r\n");
  247.                   break;
  248.                 default:
  249.                   DOOR_WriteText("Started!\r\n");
  250.                   break;
  251.               }
  252.               switch(toupper(inputstr[0]))
  253.               {
  254.                 case '\0':
  255.                 case ' ':
  256.                 case 'S':
  257.                 case 'G':
  258.                   if (transfertype==T_UPLOAD)
  259.                   {
  260.                     if (stricmp(PNode->modulename,"CLIProtocol")==0)
  261.                     {
  262.                       sprintf(options,"%s D=%s %s",PNode->moduleopts,N_ND->NodeSettings.NodePlayPen,filetype==T_NONWAREZ ? "NONWAREZ" : "");
  263.                       DOOR_SystemDoor(PNode->modulename,options);
  264.                     }
  265.                     else
  266.                     if (stricmp(PNode->modulename,"XPR")==0)
  267.                     {
  268.                       sprintf(options,"%s S D=%s",PNode->moduleopts,N_ND->NodeSettings.NodePlayPen);
  269.                       DOOR_SystemDoor(PNode->modulename,options);
  270.                     }
  271.                   }
  272.                   if (transfertype==T_DOWNLOAD)
  273.                   {
  274.  
  275.                     if (stricmp(PNode->modulename,"CLIProtocol")==0)
  276.                     {
  277.                       DOOR_WriteText("This download method is only temporary!\r\n");
  278.                       StillOK=TRUE;
  279.  
  280.                       while ((Tag = (struct TaggedFile *)N_ND->TaggedFileList->lh_Head) &&
  281.                              (Tag ->node.ln_Succ) &&
  282.                              (StillOK) &&
  283.                              (N_ND->OnlineStatus==OS_ONLINE) &&
  284.                              (!CarrierLost()))
  285.                       {
  286.                         sprintf(options,"%s U=%s %s",PNode->moduleopts,Tag->node.ln_Name,filetype==T_NONWAREZ ? "NONWAREZ" : "");
  287.                         DOOR_SystemDoor(PNode->modulename,options);
  288.                         if (strcmp(N_ND->DoorReturn,"0")==0 && N_ND->OnlineStatus==OS_ONLINE)
  289.                         {
  290.                           // deduct creds if transfer OK..
  291.                           N_ND->User.CallData.DownloadFiles++;
  292.                           N_ND->User.NormalData.DownloadFiles++;
  293.                           N_ND->User.CallData.ActualDownloadFiles++;
  294.                           N_ND->User.NormalData.ActualDownloadFiles++;
  295.  
  296.                           N_ND->User.CallData.DownloadBytes+=Tag->FileSize;
  297.                           N_ND->User.NormalData.DownloadBytes+=Tag->FileSize;
  298.                           N_ND->User.CallData.ActualDownloadBytes+=Tag->FileSize;
  299.                           N_ND->User.NormalData.ActualDownloadBytes+=Tag->FileSize;
  300.  
  301.                           // and remove the taged file
  302.                           FreeStr(Tag->node.ln_Name);
  303.                           Remove((struct Node*)Tag);
  304.                           FreeVec(Tag);
  305.                           N_ND->TaggedFiles--;
  306.  
  307.                         }
  308.                         else
  309.                         {
  310.                           StillOK=FALSE;
  311.                         }
  312.                       }
  313.                     }
  314.                     else
  315.                     {
  316.                       if (stricmp(PNode->modulename,"XPR")==0)
  317.                       {
  318.                         sprintf(options,"%s TAGS C",PNode->moduleopts);
  319.                         DOOR_SystemDoor(PNode->modulename,options);
  320.                       }
  321.                     }
  322.                   }
  323.                   break;
  324.               }
  325.               if (inputstr[0]=='G')
  326.               {
  327.                 DOOR_MenuPrompt("Press [Return] to cancel auto-logout, or [L]ogout Now >",' ');
  328.                 doorret=DOOR_GetLine(GL_EDIT|GL_DISPLAY,'\0',1,5,NULL);
  329.                 DOOR_WriteText("\r\n");
  330.                 if (doorret==IN_TIMEOUT || toupper(N_ND->CurrentLine[0])=='L')
  331.                 {
  332.                   DOOR_UserDoor("G","NOPROMPT");
  333.                 }
  334.               }
  335.             }
  336.           }
  337.  
  338.         }
  339.         else
  340.         {
  341.           DOOR_WriteText("You have selected a type of transfer that this protocol\r\n"
  342.                          "either does not support or has been disabled by the sysop!\r\n");
  343.         }
  344.       }
  345.  
  346.  
  347.     }
  348.     else DOOR_WriteText("Invalid Protocol!\r\n");
  349.   }
  350.   DOOR_Return("NOBATCH");
  351. }
  352.  
  353. int main(int argc,char *argv[])
  354. {
  355.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  356.   {
  357.     printf("Invalid/No Paramaters for door!\n");
  358.     exit (20);
  359.   }
  360.   init("Transfer");
  361.  
  362.   if (BBSGlobal=HBBS_GimmeBBS())
  363.   {
  364.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  365.     {
  366.       DoorMain(argc,argv);
  367.     }
  368.   }
  369.   cleanup(0);
  370. }
  371.